package kernel

import (
	"util/log"
	"util/pool"
)

func (bo *GameObject) SetCapacity(c int) {
	if bo.capacity != 0 {
		log.LogError("(SetCapacity) already run")
		return
	}

	bo.capacity = c
	bo.children = pool.PoolList{}
	if c == -1 {
		bo.children.Init(-1, 16)
	} else {
		bo.children.Init(c, c)
	}
}

func (bo *GameObject) AddChild(index int, child GameObjecter) int {
	if child.Parent() != nil {
		return -1
	}

	var res int

	if res = bo.children.AddObject(index, child); res == -1 {
		return -1
	}

	child.SetParent(bo)

	return res
}

func (bo *GameObject) RemoveChild(child GameObjecter) bool {

	parent := GameObjecter(bo)
	if child.Parent() != parent {
		return false
	}

	return bo.children.DelObjectByPtr(child)
}
